//
//  HudView.swift
//  MyWeatherApp
//
//  Created by Shengbing Li (QXU7859) on 2021/2/27.
//  Copyright © 2021 shanghai. All rights reserved.
//

import UIKit

class HudView: UIView {
    
    static var share: HudView = HudView()
    private lazy var activityIndicator: UIActivityIndicatorView = {
        let activity = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.large)
        activity.color = UIColor.black
        return activity
    }()
    private lazy var T: UIView = UIView()
    
    func beginHud<T: UIView>(T: T) {
        self.T = T
        T.addSubview(activityIndicator)
        activityIndicator.center = UIApplication.shared.windows.first?.center ?? T.center 
        activityIndicator.startAnimating()
    }
    
    func HideHud() {
        for v in self.T.subviews {
            if v .isEqual(self.activityIndicator) {
                v.removeFromSuperview()
            }
        }
        activityIndicator.stopAnimating()
    }
}
